<template>
  <div id="login">
    <!-- 登录内容区域 -->
    <div class="content">
      <div class="logo">
        <img src="@/assets/images/sider/logo.png" alt="" />
      </div>
      <p class="admin">人力端管理后台</p>
      <div class="form">
        <a-form-model ref="ruleForm" :model="form" :rules="rules">
          <a-form-model-item prop="account">
            <a-input
              v-model="form.account"
              placeholder="请输入管理员账号"
              size="large"
            />
          </a-form-model-item>
          <a-form-model-item prop="password">
            <a-input-password
              v-model="form.password"
              placeholder="请输入登录密码"
              size="large"
            />
          </a-form-model-item>
          <a-form-model-item>
            <a-button type="primary" :loading="loading" @click="submit"
              >登录
            </a-button>
          </a-form-model-item>
        </a-form-model>
      </div>
      <!-- 页脚区域 -->
      <div class="footer">
        <p>版权所有：湖北省创新人力资源服务中心有限公司</p>
        <p>由武汉梦软科技有限公司提供技术支持</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getTenant, login } from '@/api/login'
import local from '@/utils/local'
export default {
  name: 'login',
  data() {
    return {
      form: {
        account: 'ceshi',
        password: '123456',
        grantType: 'captcha',
        loginType: 'used'
      },
      rules: {
        account: [{ required: true, message: '请输入账号' }],
        password: [{ required: true, message: '请输入密码' }]
      },
      loading: false
    }
  },
  methods: {
    // 登录
    submit() {
      this.$refs.ruleForm.validate(async valid => {
        // 验证登录框
        if (valid) {
          this.loading = true
          local.clear()
          // 获取tenant
          const { data } = await getTenant({ account: this.form.account })
          local.set('tenant', data)
          // 登录
          const loginInfo = await login(this.form)
          local.set('token', loginInfo.data.token)
          local.set('account', loginInfo.data.account)
          if (loginInfo.code === 200) this.$message.success('登录成功')
          this.$router.push('/home')
        } else {
          this.loading = false
          return false
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
#login {
  background: url('../../assets/images/sider/bgc.png') no-repeat;
  background-position: center;
  height: 100%;
  width: 100%;
  background-size: cover;
  position: fixed;
  .admin {
    margin: 40px 0;
    width: 126px;
    height: 26px;
    font-size: 18px;
    color: #333333;
    line-height: 26px;
  }
}
.content {
  width: 760px;
  height: 456px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  transform: translate(-50%, -50%);
  .ant-form-model {
    display: flex;
  }
}
.logo {
  width: 211px;
  height: 40px;
  img {
    width: 100%;
    height: 100%;
  }
}
.ant-btn {
  width: 356px;
  height: 50px;
  background: #0096ff;
  margin-top: 32px;
}
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: -100px;
  left: 50%;
  transform: translateX(-50%);
  p {
    color: #797979;
    font-size: 14px;
    line-height: 20px;
    margin-bottom: 14px !important;
  }
}
</style>
